
#region Imported Namespaces
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Drawing;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using PHSRAG.Insight21.Context;
using PHSRAG.Insight21.SearchContext;
using AlphaPicker = PHSRAG.WebControls.AlphaPicker;
using Annunciator = PHSRAG.WebControls.Annunciator;
using DataAccess = PHSRAG.Utility.DataAccess;
using Settings = PHSRAG.Utility.Settings;
using Pager = PHSRAG.WebControls.Pager;
#endregion

namespace PHSRAG.Insight21.ClinicalTrials.Controls
{
    #region Class ProcedurePicker
    /// <summary>
    /// The ProcedurePicker is very similar to Picker control except that it is not integrated with CommonSearch.
    /// The ItemCommand handler calls back to the opening page to set controls with the selected data.
    /// See Picker.ascx for more information.
    /// </summary>
    public partial class ProcedurePicker : System.Web.UI.UserControl
    {
        #region Constants
        private const string ClientScriptKey = "clientScript_A0BB452C-E797-4d74-8853-C8A54627F8BF";
        private const string DataKey = "data_D37CDC12-7227-4556-9954-8145BD4D198B";
        private const string FilteredDataKey = "filtered_D37CDC12-7227-4556-9954-8145BD4D198B";
        private const string JavascriptViewAllCallback = "ResetPickerState";
        private const string JavascriptWindowTitle = "SetWindowTitle";
        private const string PickerFilterColumn = "Description";
        #endregion

        #region Instance Variables (protected)
        /// <summary>The AlphaPicker helps in narrowing down the list of displayed items in the datagrid.</summary>

        /// <summary>The annunciator is used to display warning and error messages.</summary>

        /// <summary>The data grid displays data associated with a pick type.</summary>

        /// <summary>The page is used to paginate through the data grid.</summary>

        /// <summary>The button which instigates a search (and subsquent filtering).</summary>

        /// <summary>This control is used both by the PI and Lab picker, and the label may be set as appropirate.</summary>

        /// <summary>This control is used both by the PI and Lab picker, and the label may be set as appropirate.</summary>

        /// <summary>The text to use (if any) as a filter while loading the datagrid.</summary>

        /// <summary>The text to use (if any) as a filter while loading the datagrid.</summary>
        #endregion

        #region Private Instance Variables
        private DataTable pickerTable;
        private DataTable alphaTable;
        private enum pickerColumns
        {
            numberOfProcedures,
            ChargeCode,
            Department,
            Description,
            DescriptionLabel,
            CPTCode,
            ChargeCodeVisible,
            Location,
            Price,
            IndustryRate,
            GovernmentRate,
            ResearchRate,
            ResearchCharge,
            IndustryCharge,
            GovernmentCharge,
            ProFee,
            POTechFee,
            NFPOTechFee,
            POProFee,
            NFPOProFee
        }
        private Policy.ICachePolicy objectCachePolicy;

        #endregion

        #region Private Properties
        /// <summary>
        /// Get/Set the data used to initialize the AlphaPicker and the data grid. So as to avoid multiple hits on the
        /// database, the retrieved data is cached under a picker-specific key.
        /// </summary>
        private DataTable FilteredData
        {
            get
            {
                DataTable filteredDataTable = Session[FilteredDataKey] as DataTable;
                return (filteredDataTable != null) ? filteredDataTable : PickerData;
            }
            set
            {
                Session[FilteredDataKey] = value;
            }
        }

        /// <summary>
        /// Get/Set the data used to initialize the AlphaPicker and the data grid. So as to avoid multiple hits on the
        /// database, the retrieved data is cached under a picker-specific key.
        /// </summary>
        private DataTable PickerData
        {
            get
            {
                //Set the alpha picker to the letter of the description if there is one.
                if (searchDescription.Text.Trim() != "") alphaPicker.Selection =  searchDescription.Text.Trim().Substring(0, 1);

                if (pickerTable.TableName != "Search")
                    pickerTable = Session[DataKey] as DataTable;
                else
                {
                    Budget budget = (Budget)((Policy.ICachePolicy)Session[Policy.Names.CachePolicyKey]).GetCachedObject(Budget.CacheKey);


                    string studyType = budget != null ? budget.StudyType :Convert.ToString( Session["SponsorChargeRate"]);
                    pickerTable = new DataTable("Procedures");
                    DataAccess.LoadDataTable(pickerTable, DataAccess.ConnectionString, "GetProcedurePrices",
                      Utility.DataAccess.BuildSqlParameterArray("@institution", SqlDbType.VarChar, Request.QueryString["Institution"],
                                                                 "@sponsorType", SqlDbType.VarChar, studyType,
                                                                 "@IsNonFacility", SqlDbType.Bit, (GlobalPricing.Checked) ? 1 : 0,
                                                                 "@CPTCode", SqlDbType.VarChar, (searchCPTCode.Text.Trim() == "") ? null : searchCPTCode.Text.Trim(),
                                                                 "@ChargeCode", SqlDbType.Int, Convert.ToInt32((searchChargeCode.Text.Trim() == "") ? null : searchChargeCode.Text.Trim()),
                                                                 "@Description", SqlDbType.VarChar, (searchDescription.Text.Trim() == "") ? (alphaPicker.Selection != "") ? alphaPicker.Selection : null : searchDescription.Text.Trim(),
                                                                 "@UsePOPricing", SqlDbType.Bit, (GlobalPricing.Checked) ? 1 : 0));
                    Session[DataKey] = pickerTable;
                }
                return pickerTable;
            }
        }
        #endregion

        #region Pagination Event Handlers
        /// <summary>
        /// Handler for the FirstPage event raised by the Pager. Force the data grid to display the first page.
        /// </summary>
        /// <param name="sender">Page control</param>
        /// <param name="e">Arguments associated with the event</param>
        /// <remarks>
        /// If the data grid is already displaying the first page, no further action is taken.
        /// </remarks>
        private void OnFirstPage(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            dataGrid.CurrentPageIndex = 0;
            LoadDataGrid();
        }

        /// <summary>
        /// Handler for the LastPage event raised by the Pager. Force the data grid to display the last page.
        /// </summary>
        /// <param name="sender">Page control</param>
        /// <param name="e">Arguments associated with the event</param>
        /// <remarks>
        /// If the data grid is already displaying the last page, no further action is taken.
        /// </remarks>
        private void OnLastPage(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            dataGrid.CurrentPageIndex = pager.PageCount - 1;
            LoadDataGrid();
        }

        /// <summary>
        /// Handler for the NextPage event raised by the Pager. Force the data grid to display the next page.
        /// </summary>
        /// <param name="sender">Page control</param>
        /// <param name="e">Arguments associated with the event</param>
        /// <remarks>
        /// If the data grid is already displaying the last page, no further action is taken.
        /// </remarks>
        private void OnNextPage(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            if (dataGrid.CurrentPageIndex < (pager.PageCount - 1))
            {
                dataGrid.CurrentPageIndex++;
                LoadDataGrid();
            }
        }
        /// <summary>
        /// Load the DataGrid with PI data. The name of the stored procedure to be used for the load is specified by
        /// the invoking entity via QueryString using the key "DataLoader".
        /// Initialize the Pager based on the volume of data retrieved from the database. The navigation links on the
        /// Pager are also set.
        /// </summary>
        /// <remarks>
        /// The data that is loaded into the data grid is filtered based upon the selection in the alpha picker.
        /// </remarks>
        private void LoadDataGrid()
        {
            DataTable pickerData = FilteredData;
            pager.RecordCount = pickerData.Rows.Count;

            int pageCount = (pager.RecordCount / dataGrid.PageSize) + (int)(((pager.RecordCount % dataGrid.PageSize) == 0) ? 0 : 1);
            pager.PageCount = pageCount;
            pager.CurrentPage = dataGrid.CurrentPageIndex + 1;	// Pager uses 1-based index.

            dataGrid.DataSource = pickerData;
            dataGrid.DataBind();

            //if BWH and on summary page display 2 rates (Gov and Industry) and hide ResearchRate.
            if (Request.QueryString["Caller"] == "budgetBuilderSummary")
                if (Request.QueryString["Institution"] == "ClinicalTrialBudgetInstitutionBWH")
                {
                    dataGrid.Columns[(int)pickerColumns.ResearchRate].Visible = false;
                    dataGrid.Columns[(int)pickerColumns.ResearchCharge].Visible = false;
                }
                else
                {
                    dataGrid.Columns[(int)pickerColumns.GovernmentRate].Visible = false;
                    dataGrid.Columns[(int)pickerColumns.IndustryRate].Visible = false;
                    dataGrid.Columns[(int)pickerColumns.GovernmentCharge].Visible = false;
                    dataGrid.Columns[(int)pickerColumns.IndustryCharge].Visible = false;
                }
            else
            {
                dataGrid.Columns[(int)pickerColumns.ResearchRate].Visible = false;
                dataGrid.Columns[(int)pickerColumns.GovernmentRate].Visible = false;
                dataGrid.Columns[(int)pickerColumns.IndustryRate].Visible = false;
                dataGrid.Columns[(int)pickerColumns.GovernmentCharge].Visible = false;
                dataGrid.Columns[(int)pickerColumns.IndustryCharge].Visible = false;
            }


            alphaPicker.Visible = searchDescriptionLabel.Visible = searchDescription.Visible = search.Visible = pager.Visible = (dataGrid.Items.Count > 0);

            if (pager.Visible)
            {
                int startIndex = dataGrid.CurrentPageIndex * dataGrid.PageSize;
                pager.FirstRecord = startIndex + 1;
                pager.LastRecord = startIndex + Math.Min(startIndex + dataGrid.PageSize, dataGrid.Items.Count);

                ManageNavigationLinks();
            }
            else
            {
                annunciator.Title = "Data Load Warning:";
                annunciator.Message = "No Procedure data found.";
                annunciator.Visible = true;
                dataGrid.Visible = false;

                Controls.Add(new LiteralControl(
                    "<input type=\"button\" class=\"Button\" value=\"Close Window\" onclick=\"window.close();return false;\">"));
            }
        }

        /// <summary>
        /// Handler for the PreviousPage event raised by the Pager. Force the data grid to display the previous page.
        /// </summary>
        /// <param name="sender">Page control</param>
        /// <param name="e">Arguments associated with the event</param>
        /// <remarks>
        /// If the data grid is already displaying the first page, no further action is taken.
        /// </remarks>
        private void OnPreviousPage(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            if (dataGrid.CurrentPageIndex > 0)
            {
                dataGrid.CurrentPageIndex--;
                LoadDataGrid();
            }
        }
        #endregion

        #region Overrides
        /// <summary>
        /// Register clientside scripts.
        /// </summary>
        /// <param name="e">Argument associated with the event.</param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            RegisterClientScripts();
        }
        #endregion

        #region Event Handlers
        /// <summary>
        /// Handler for the event raised by the DataGrid when a row is clicked upon.
        /// </summary>
        /// <param name="source">DataGrid control</param>
        /// <param name="e">Arguments associated with the event</param>
        /// <remarks>
        /// The item command is raised when the user clicks on the LastName column for a row. That column contains a
        /// LinkButton whose CommandName is set to "Select". Events raised for any other reason are ignored.
        /// </remarks>
        private void OnItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                string name = (e.Item.Cells[(int)pickerColumns.Description].Controls[0] as LinkButton).Text;
                string chargeCode = e.Item.Cells[(int)pickerColumns.ChargeCode].Text;
                string techFee = "0";
                techFee = (HospitalPricing.Checked == true || SplitPricing.Checked == true) ? 
                                            e.Item.Cells[(int)pickerColumns.Price].Text
                                            : e.Item.Cells[(int)pickerColumns.NFPOTechFee].Text;
                string proFee = "0";
                proFee = (HospitalPricing.Checked == true) ? e.Item.Cells[(int)pickerColumns.ProFee].Text
                                                        : (SplitPricing.Checked == true)? 
                                                            e.Item.Cells[(int)pickerColumns.POProFee].Text
                                                            : e.Item.Cells[(int)pickerColumns.NFPOProFee].Text;

                Session.Remove(FilteredDataKey);

                // Generate client-side script to close the window within which this control is loaded. In addition, a
                // is made to a javascript functino on the opener page to display the choice made.

                if (!Page.ClientScript.IsClientScriptBlockRegistered(ClientScriptKey))
                {
                    string script = string.Format(
                        "<script language=\"javascript\">\n" +
                        "window.opener.SetProcedureSelection(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\", \"{6}\");\n" +
                        "window.close();\n\n" +
                        "</script>\n", chargeCode, name, Request.QueryString["Caller"], techFee, proFee, (HospitalPricing.Checked==true)?1:0, (GlobalPricing.Checked==false)?1:0);

                    Page.ClientScript.RegisterClientScriptBlock(GetType(), ClientScriptKey, script);
                }
            }
        }
        /// <summary>
        /// If the user uses the checkboxes to select multiple procedures or the checkboxes to select many of one type of procedure 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnProcedureSelect(object sender, System.EventArgs e)
        {
            int howManyProcedures = 0;
            Budget budget = (Budget)((Policy.ICachePolicy)Session[Policy.Names.CachePolicyKey]).GetCachedObject(Budget.CacheKey);
            foreach (DataGridItem item in dataGrid.Items)
            {
                //if the user used the textboxes to select multiple procedures 
                if (((TextBox)item.Cells[(int)pickerColumns.numberOfProcedures].Controls[1]).Text != string.Empty)
                {
                    int numberOfProcedures = Convert.ToInt32(((TextBox)item.Cells[(int)pickerColumns.numberOfProcedures].Controls[1]).Text);

                    //Start index at one because it is one less than what they type in since the original 
                    //procedure they pick will up the count 
                    if (numberOfProcedures == 1)
                    {
                        int chargeCode = Convert.ToInt32(item.Cells[(int)pickerColumns.ChargeCode].Text);
                        string name = (item.Cells[(int)pickerColumns.Description].Controls[0] as LinkButton).Text;
                        string techFee = "0";
                        techFee = (HospitalPricing.Checked == true || SplitPricing.Checked == true) ?
                                                    item.Cells[(int)pickerColumns.Price].Text
                                                    : item.Cells[(int)pickerColumns.NFPOTechFee].Text;
                        string proFee = "0";
                        proFee = (HospitalPricing.Checked == true) ? item.Cells[(int)pickerColumns.ProFee].Text
                                                                : (SplitPricing.Checked == true) ?
                                                                    item.Cells[(int)pickerColumns.POProFee].Text
                                                                    : item.Cells[(int)pickerColumns.NFPOProFee].Text;

                        if (!Page.ClientScript.IsClientScriptBlockRegistered(GetType(), ClientScriptKey))
                        {
                            string script = string.Format(
                                "<script language=\"javascript\">\n" +
                                "window.opener.SetProcedureSelection(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\", \"{6}\");\n" +
                                "window.close();\n\n" +
                                "</script>\n", chargeCode, name, Request.QueryString["Caller"], techFee, proFee, (HospitalPricing.Checked == true) ? 1 : 0, (GlobalPricing.Checked == false) ? 1 : 0);
                            Page.ClientScript.RegisterClientScriptBlock(GetType(), ClientScriptKey, script);
                        }
                    }
                    else
                    {
                        for (int i = 1; i < numberOfProcedures; i++)
                        {
                            int chargeCode = Convert.ToInt32(item.Cells[(int)pickerColumns.ChargeCode].Text);

                            string name = (item.Cells[(int)pickerColumns.Description].Controls[0] as LinkButton).Text;
                            string techFee = "0";
                            techFee = (HospitalPricing.Checked == true || SplitPricing.Checked == true) ?
                                                        item.Cells[(int)pickerColumns.Price].Text
                                                        : item.Cells[(int)pickerColumns.NFPOTechFee].Text;
                            string proFee = "0";
                            proFee = (HospitalPricing.Checked == true) ? item.Cells[(int)pickerColumns.ProFee].Text
                                                                    : (SplitPricing.Checked == true) ?
                                                                        item.Cells[(int)pickerColumns.POProFee].Text
                                                                        : item.Cells[(int)pickerColumns.NFPOProFee].Text;

                            string procedureCost = item.Cells[(int)pickerColumns.Price].Text;
                            //string proFee = item.Cells[(int)pickerColumns.ProFee].Text;

                            BudgetProcedures budgetProcedures = budget.BudgetProcedures;
                            BudgetProcedure newBudgetProcedure = budgetProcedures.CreateNewBudgetProcedure();
                            newBudgetProcedure.ProcedureName = name;
                            newBudgetProcedure.ProcedureCost = procedureCost;
                            newBudgetProcedure.ProcedureChargeCode = chargeCode;
                            newBudgetProcedure.ProfessionalFee = proFee;
                            newBudgetProcedure.UseHospitalPricing = HospitalPricing.Checked;
                            newBudgetProcedure.IsFacility = !GlobalPricing.Checked;

                            if (!Page.ClientScript.IsClientScriptBlockRegistered(GetType(), ClientScriptKey))
                            {
                                string script = string.Format(
                                "<script language=\"javascript\">\n" +
                                "window.opener.SetProcedureSelection(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\", \"{6}\");\n" +
                                "window.close();\n\n" +
                                "</script>\n", chargeCode, name, Request.QueryString["Caller"], techFee, proFee, (HospitalPricing.Checked == true) ? 1 : 0, (GlobalPricing.Checked == false) ? 1 : 0);
                                Page.ClientScript.RegisterClientScriptBlock(GetType(), ClientScriptKey, script);
                            }
                        }
                    }
                }
                //If the user used the checkboxes to select multiple procedures 
                if (((TextBox)item.Cells[(int)pickerColumns.numberOfProcedures].Controls[1]).Text!="")
                {
                    int chargeCode = Convert.ToInt32(item.Cells[(int)pickerColumns.ChargeCode].Text);
                    string name = (item.Cells[(int)pickerColumns.Description].Controls[0] as LinkButton).Text;
                    string procedureCost;
                    if (item.Cells[(int)pickerColumns.Price].Text == "&nbsp;")
                        procedureCost = "0";
                    else
                        procedureCost = item.Cells[(int)pickerColumns.Price].Text;
                    //string proFee = (item.Cells[(int)pickerColumns.ProFee].Text == "&nbsp;")? "0" : item.Cells[(int)pickerColumns.ProFee].Text;
                    string techFee = "0";
                    techFee = (HospitalPricing.Checked == true || SplitPricing.Checked == true) ?
                                                item.Cells[(int)pickerColumns.Price].Text
                                                : item.Cells[(int)pickerColumns.NFPOTechFee].Text;
                    string proFee = "0";
                    proFee = (HospitalPricing.Checked == true) ? item.Cells[(int)pickerColumns.ProFee].Text
                                                            : (SplitPricing.Checked == true) ?
                                                                item.Cells[(int)pickerColumns.POProFee].Text
                                                                : item.Cells[(int)pickerColumns.NFPOProFee].Text;

                    howManyProcedures++;
                    if (howManyProcedures > 1)
                    {
                        BudgetProcedures budgetProcedures = budget.BudgetProcedures;
                        BudgetProcedure newBudgetProcedure = budgetProcedures.CreateNewBudgetProcedure();
                        newBudgetProcedure.ProcedureName = name;
                        newBudgetProcedure.ProcedureCost = procedureCost;
                        newBudgetProcedure.ProcedureChargeCode = chargeCode;
                        newBudgetProcedure.ProfessionalFee = proFee;
                        newBudgetProcedure.UseHospitalPricing = HospitalPricing.Checked;
                        newBudgetProcedure.IsFacility = !GlobalPricing.Checked;
                    }

                    if (!Page.ClientScript.IsClientScriptBlockRegistered(ClientScriptKey))
                    {
                        string script = string.Format(
                        "<script language=\"javascript\">\n" +
                        "window.opener.SetProcedureSelection(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\", \"{6}\");\n" +
                       "window.close();\n\n" +
                        "</script>\n", chargeCode, name, Request.QueryString["Caller"], techFee, proFee, (HospitalPricing.Checked == true) ? 1 : 0, (GlobalPricing.Checked == false) ? 1 : 0);
                        Page.ClientScript.RegisterClientScriptBlock(GetType(), ClientScriptKey, script);
                    }
                }
            }
        }

        /// <summary>
        /// On first load of the control, initialize the AlphaPicker and load the DataGrid with PI data.
        /// </summary>
        /// <param name="sender">Control being loaded</param>
        /// <param name="e">Argument associated with the event</param>
        private void OnPageLoad(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                pickerTable = new DataTable("Procedures");
                alphaTable = new DataTable("Procedures");
                alphaPicker.DataSource = alphaTable;
                alphaPicker.DataColumn = PickerFilterColumn;
                alphaPicker.JavascriptViewAllCallback = JavascriptViewAllCallback;
                alphaPicker.Selection = "";
                searchDescriptionLabel.Text = "Description";
                searchCPTCodeLabel.Text = "CPTCode";
                searchChargeCodeLabel.Text = "Charge Code";
                dataGrid.PageSize = Settings.GetKeyValue("DataGrid.ItemsPerPage", 10);
                doneSelectingProcedures.Visible = false;
                HospitalPricing.Checked = false;
                SplitPricing.Checked = true;
                GlobalPricing.Checked = false;

            }
            if (Request.QueryString["Caller"] == "budgetBuilderSummary")
            {
                ChoosePricingPanel.Visible = false;
                HospitalPricing.Checked = false;
                SplitPricing.Checked = false;
                GlobalPricing.Checked = true;
            }

            //If this is not coming from the budget builder summary then turn on all panels

            if (objectCachePolicy.GetCachedObject(Keys.IsFromBudgetBuilderSummaryKey) == null)
            {
                dataGrid.Columns[(int)pickerColumns.Description].Visible = true;
                dataGrid.Columns[(int)pickerColumns.DescriptionLabel].Visible = false;
                dataGrid.Columns[(int)pickerColumns.numberOfProcedures].Visible = true;
            }
            else
            {
                //If this is coming from the budget builder summary then turn off 
                //number of procedures column, Link button description, fees panel.
                dataGrid.Columns[(int)pickerColumns.Description].Visible = false;
                dataGrid.Columns[(int)pickerColumns.DescriptionLabel].Visible = true;
                dataGrid.Columns[(int)pickerColumns.numberOfProcedures].Visible = false;
                doneSelectingProcedures.Visible = false;

            }

        }

        /// <summary>
        /// Handler for the Search button. Helps in filtering the data displayed in the data grid.
        /// </summary>
        /// <param name="sender">The control which raised the event</param>
        /// <param name="e">Argument associated with the event</param>
        /// <remarks>
        /// <p>There are two inputs to the search action:</p>
        /// <list type="bullet">
        /// <item><description>An alphabet from the AlphaPicker</description></item>
        /// <item><description>Free-form text typed in the search text box</description></item>
        /// </list>
        /// <p>If any text is explicitly typed in the text box, it will override any alphabet selection.</p>
        /// <p>A search always implies displaying the first page of the data grid.</p>
        /// </remarks>
        protected void OnSearch(object sender, System.EventArgs e)
        {
            try
            {
                pickerTable = new DataTable("Search");
                FilteredData = PickerData;
                if (FilteredData.Rows.Count > 0)
                {
                    dataGrid.CurrentPageIndex = 0;
                    LoadDataGrid();
                    dataGrid.Visible = pager.Visible = true;
                    if (objectCachePolicy.GetCachedObject(Keys.IsFromBudgetBuilderSummaryKey) == null)
                        doneSelectingProcedures.Visible = true;
                    else doneSelectingProcedures.Visible = false;
                    annunciator.Message = "";

                    if (Request.QueryString["Caller"] != "budgetBuilderSummary")
                    {
                        //Undo highlighting on the header row for charges that will be used.
                        dataGrid.Columns[(int)pickerColumns.ResearchCharge].HeaderStyle.Font.Bold = false;
                        dataGrid.Columns[(int)pickerColumns.ProFee].HeaderStyle.Font.Bold = false;
                        dataGrid.Columns[(int)pickerColumns.POProFee].HeaderStyle.Font.Bold = false;
                        dataGrid.Columns[(int)pickerColumns.NFPOTechFee].HeaderStyle.Font.Bold = false;
                        dataGrid.Columns[(int)pickerColumns.NFPOProFee].HeaderStyle.Font.Bold = false;
                        dataGrid.Columns[(int)pickerColumns.ResearchCharge].ItemStyle.Font.Bold = false;
                        dataGrid.Columns[(int)pickerColumns.ProFee].ItemStyle.Font.Bold = false;
                        dataGrid.Columns[(int)pickerColumns.POProFee].ItemStyle.Font.Bold = false;
                        dataGrid.Columns[(int)pickerColumns.NFPOTechFee].ItemStyle.Font.Bold = false;
                        dataGrid.Columns[(int)pickerColumns.NFPOProFee].ItemStyle.Font.Bold = false;

                        if (HospitalPricing.Checked)
                        {
                            dataGrid.Columns[(int)pickerColumns.ResearchCharge].HeaderStyle.Font.Bold = true;
                            dataGrid.Columns[(int)pickerColumns.ProFee].HeaderStyle.Font.Bold = true;
                            dataGrid.Columns[(int)pickerColumns.ResearchCharge].ItemStyle.Font.Bold = true;
                            dataGrid.Columns[(int)pickerColumns.ProFee].ItemStyle.Font.Bold = true;
                        }
                        if (SplitPricing.Checked)
                        {
                            dataGrid.Columns[(int)pickerColumns.ResearchCharge].HeaderStyle.Font.Bold = true;
                            dataGrid.Columns[(int)pickerColumns.POProFee].HeaderStyle.Font.Bold = true;
                            dataGrid.Columns[(int)pickerColumns.ResearchCharge].ItemStyle.Font.Bold = true;
                            dataGrid.Columns[(int)pickerColumns.POProFee].ItemStyle.Font.Bold = true;
                        }
                        if (GlobalPricing.Checked)
                        {
                            dataGrid.Columns[(int)pickerColumns.NFPOTechFee].HeaderStyle.Font.Bold = true;
                            dataGrid.Columns[(int)pickerColumns.NFPOProFee].HeaderStyle.Font.Bold = true;
                            dataGrid.Columns[(int)pickerColumns.NFPOTechFee].ItemStyle.Font.Bold = true;
                            dataGrid.Columns[(int)pickerColumns.NFPOProFee].ItemStyle.Font.Bold = true;
                        }
                    }
                }
                else
                {
                    annunciator.Title = "Data Load Warning:";
                    annunciator.Message = "No Procedure data found matching the search criteria.";
                    annunciator.Visible = true;
                    dataGrid.Visible = pager.Visible = false;
                    doneSelectingProcedures.Visible = false;
                }
            }
            catch
            {
                annunciator.Title = "Data Load Warning:";
                annunciator.Message = "No Procedure data found matching the search criteria.";
                annunciator.Visible = true;
                dataGrid.Visible = pager.Visible = false;
            }
        }

        /// <summary>
        /// Set the First/Last/Next/Previous page links on the Pager control to enabled/disabled based on which page is
        /// being displayed in the DataGrid.
        /// The First/Previous links are disabled if the first page is being displayed.
        /// The Last/Next links are disabled if the last page is being displayed.
        /// </summary>
        private void ManageNavigationLinks()
        {
            pager.EnableFirstPage = pager.EnablePreviousPage = (dataGrid.CurrentPageIndex != 0);
            pager.EnableLastPage = pager.EnableNextPage = (dataGrid.CurrentPageIndex != (pager.PageCount - 1));
        }

        private void RegisterClientScripts()
        {
            if (!Page.ClientScript.IsClientScriptBlockRegistered(JavascriptViewAllCallback))
            {
                string script = string.Format(
                    "<script language=\"javascript\">\n" +
                    "function {0}()\n" +
                    "{{\n" +
                    "\tvar textbox = document.getElementById('{1}');\n" +
                    "\tif (textbox != null)\n" +
                    "\t\ttextbox.value = '';\n" +
                    "}}\n" +
                    "</script>\n", JavascriptViewAllCallback, searchDescription.ClientID);

                Page.ClientScript.RegisterClientScriptBlock(GetType(), JavascriptViewAllCallback, script);
            }

            if (!Page.ClientScript.IsClientScriptBlockRegistered(JavascriptWindowTitle))
            {
                string script2 = string.Format(
                    "<script language=\"javascript\">\n" +
                    "\twindow.pageTitle.text = \"Procedure Search\";\n" +
                    "</script>\n");

                Page.ClientScript.RegisterClientScriptBlock(GetType(), JavascriptWindowTitle, script2);
            }
        }
        #endregion

        #region Web Form Designer generated code
        /// <summary>
        /// Initialize the control. Create dynamic columns in the data grid based on the pick type.
        /// </summary>
        /// <param name="e">Argument associated with the event</param>
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
            objectCachePolicy = (Policy.ICachePolicy)Session[Policy.Names.CachePolicyKey];
            searchDescription.Attributes["onchange"] = string.Format("{0}();", AlphaPicker.JavascriptResetFunction);
        }

        /// <summary>
        ///		Required method for Designer support - do not modify
        ///		the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pager.FirstPage += new System.Web.UI.WebControls.CommandEventHandler(this.OnFirstPage);
            this.pager.PreviousPage += new System.Web.UI.WebControls.CommandEventHandler(this.OnPreviousPage);
            this.pager.NextPage += new System.Web.UI.WebControls.CommandEventHandler(this.OnNextPage);
            this.pager.LastPage += new System.Web.UI.WebControls.CommandEventHandler(this.OnLastPage);
            this.dataGrid.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.OnItemCommand);
            this.Load += new System.EventHandler(this.OnPageLoad);
            this.search.Click += new System.EventHandler(this.OnSearch);
            this.doneSelectingProcedures.Click += new System.EventHandler(OnProcedureSelect);
        }
        #endregion

        protected void dataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                if (Convert.ToInt32(e.Item.Cells[(int)pickerColumns.ChargeCodeVisible].Text) < 0)
                        e.Item.Cells[(int)pickerColumns.ChargeCodeVisible].Text = string.Empty;
            }
        }
        protected void HospitalPricing_CheckedChanged(object sender, EventArgs e)
        {
            dataGrid.Visible = false;
            HospitalPricing.Checked = true;
            SplitPricing.Checked = false;
            GlobalPricing.Checked = false;
            pager.Visible = false;
            doneSelectingProcedures.Visible = false;
        }

        protected void SplitPricing_CheckedChanged(object sender, EventArgs e)
        {
            dataGrid.Visible = false;
            HospitalPricing.Checked = false;
            SplitPricing.Checked = true;
            GlobalPricing.Checked = false;
            pager.Visible = false;
            doneSelectingProcedures.Visible = false;
        }
        protected void GlobalPricing_CheckedChanged(object sender, EventArgs e)
        {
            dataGrid.Visible = false;
            HospitalPricing.Checked = false;
            SplitPricing.Checked = false;
            GlobalPricing.Checked = true;
            pager.Visible = false;
            doneSelectingProcedures.Visible = false;
        }
}
    #endregion
}

// --- EOF ---
